home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WPrefs.app / Configurations.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-02  |  15.6 KB  |  536 lines

  1. /* Configurations.c- misc. configurations
  2.  * 
  3.  *  WPrefs - Window Maker Preferences Program
  4.  * 
  5.  *  Copyright (c) 1998 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23.  
  24. #include "WPrefs.h"
  25.  
  26. typedef struct _Panel {
  27.     WMFrame *frame;
  28.     char *sectionName;   
  29.  
  30.     char *description;
  31.  
  32.     CallbackRec callbacks;
  33.     
  34.     WMWindow *win;
  35.  
  36.     WMFrame *icoF;
  37.     WMButton *icoB[5];
  38.  
  39.     WMFrame *shaF;
  40.     WMButton *shaB[5];
  41.  
  42.     WMFrame *titlF;
  43.     WMButton *oldsB;
  44.     WMButton *newsB;
  45.  
  46.     WMFrame *animF;
  47.     WMButton *animB;
  48.     WMButton *supB;
  49.     WMButton *sfxB;
  50.     WMLabel *noteL;
  51.  
  52.     WMFrame *smoF;
  53.     WMButton *smoB;
  54.  
  55.     WMFrame *dithF;
  56.     WMButton *dithB;
  57.     WMSlider *dithS;
  58.     WMLabel *dithL;
  59.     WMLabel *dith1L;
  60.     WMLabel *dith2L;
  61.     
  62.     int cmapSize;
  63. } _Panel;
  64.  
  65.  
  66.  
  67. #define ICON_FILE    "configs"
  68.  
  69. #define OLDS_IMAGE    "oldstyle"
  70. #define NEWS_IMAGE    "newstyle"
  71.  
  72. #define ANIM_IMAGE    "animations"
  73. #define SUPERF_IMAGE    "moreanim"
  74. #define SOUND_IMAGE    "sound"
  75. #define SMOOTH_IMAGE    "smooth"
  76.  
  77. #define SPEED_IMAGE     "speed%i"
  78. #define SPEED_IMAGE_S     "speed%is"
  79.  
  80. #define ARQUIVO_XIS    "xis"
  81.  
  82.  
  83. static void updateLabel(WMWidget *self, void *data);
  84.  
  85.  
  86. static void
  87. showData(_Panel *panel)
  88. {
  89.     WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
  90.     
  91.     WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
  92.     
  93.     if (GetBoolForKey("NewStyle")) {
  94.     WMPerformButtonClick(panel->newsB);
  95.     } else {
  96.     WMPerformButtonClick(panel->oldsB);
  97.     }
  98.     
  99.     WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
  100.     
  101.     WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
  102.  
  103.     WMSetButtonSelected(panel->sfxB, !GetBoolForKey("DisableSound"));
  104.  
  105.     WMSetButtonSelected(panel->smoB, GetBoolForKey("SmoothWorkspaceBack"));
  106.  
  107.     WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
  108.     
  109.     WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
  110.  
  111.     updateLabel(panel->dithS, panel);
  112. }
  113.  
  114.  
  115. static void
  116. updateLabel(WMWidget *self, void *data)
  117. {
  118.     WMSlider *sPtr = (WMSlider*)self;
  119.     _Panel *panel = (_Panel*)data;
  120.     char buffer[64];
  121.     float fl;
  122.     
  123.     fl = WMGetSliderValue(sPtr);
  124.  
  125.     panel->cmapSize = (int)fl;
  126.     
  127.     sprintf(buffer, "%i", panel->cmapSize*panel->cmapSize*panel->cmapSize);
  128.     WMSetLabelText(panel->dithL, buffer);
  129. }
  130.  
  131.  
  132. static void
  133. createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file, 
  134.          WMPixmap **icon1,  WMPixmap **icon2)
  135. {
  136.     RImage *icon;
  137.     char *path;
  138.     RColor gray = {0xae,0xaa,0xae};
  139.  
  140.     *icon1 = NULL;
  141.     *icon2 = NULL;
  142.  
  143.     path = LocateImage(file);
  144.     if (!path) {
  145.     return;
  146.     }
  147.     
  148.     *icon1 = WMCreatePixmapFromFile(scr, path);
  149.     if (!*icon1) {
  150.     wwarning(_("could not load icon %s"), path);
  151.     free(path);
  152.     return;
  153.     }
  154.     icon = RLoadImage(rc, path, 0);
  155.     if (!icon) {
  156.     wwarning(_("could not load icon %s"), path);
  157.     free(path);
  158.     return;
  159.     }
  160.     RCombineImageWithColor(icon, &gray);
  161.     if (xis) {
  162.     RCombineImagesWithOpaqueness(icon, xis, 180);
  163.     if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
  164.         wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
  165.     }
  166.     RDestroyImage(icon);
  167.     free(path);
  168. }
  169.  
  170.  
  171.  
  172. static void
  173. createPanel(Panel *p)
  174. {
  175.     _Panel *panel = (_Panel*)p;
  176.     WMScreen *scr = WMWidgetScreen(panel->win);
  177.     char *buf1, *buf2;
  178.     WMPixmap *icon, *altIcon;
  179.     RImage *xis = NULL;
  180.     int i;
  181.     RContext *rc = WMScreenRContext(scr);
  182.     WMFont *font = WMSystemFontOfSize(scr, 10);
  183.     char *path;
  184.     
  185.     path = LocateImage(ARQUIVO_XIS);
  186.     if (path) {
  187.     xis = RLoadImage(rc, path, 0);
  188.     if (!xis) {
  189.         wwarning(_("could not load image file %s"), path);
  190.     }
  191.     free(path);
  192.     }
  193.  
  194.     panel->frame = WMCreateFrame(panel->win);
  195.     WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
  196.     WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
  197.  
  198.     /*********** Icon Slide Speed **********/
  199.     
  200.     panel->icoF = WMCreateFrame(panel->frame);
  201.     WMResizeWidget(panel->icoF, 230, 45);
  202.     WMMoveWidget(panel->icoF, 15, 10);
  203.     WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
  204.     
  205.     /*********** Shade Animation Speed **********/
  206.     panel->shaF = WMCreateFrame(panel->frame);
  207.     WMResizeWidget(panel->shaF, 230, 45);
  208.     WMMoveWidget(panel->shaF, 15, 60);
  209.     WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
  210.  
  211.     
  212.     buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
  213.     buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
  214.     
  215.     for (i = 0; i < 5; i++) {
  216.     panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
  217.     panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
  218.     WMResizeWidget(panel->icoB[i], 40, 24);
  219.     WMMoveWidget(panel->icoB[i], 10+(40*i), 15);
  220.     WMResizeWidget(panel->shaB[i], 40, 24);
  221.     WMMoveWidget(panel->shaB[i], 10+(40*i), 15);
  222.     WMSetButtonBordered(panel->icoB[i], False);
  223.     WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
  224.     if (i > 0) {
  225.         WMGroupButtons(panel->icoB[0], panel->icoB[i]);
  226.     }
  227.     WMSetButtonBordered(panel->shaB[i], False);
  228.     WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
  229.     if (i > 0) {
  230.         WMGroupButtons(panel->shaB[0], panel->shaB[i]);
  231.     }
  232.     sprintf(buf1, SPEED_IMAGE, i);
  233.     sprintf(buf2, SPEED_IMAGE_S, i);
  234.     path = LocateImage(buf1);
  235.     if (path) {
  236.         icon = WMCreatePixmapFromFile(scr, path);
  237.         if (icon) {
  238.         WMSetButtonImage(panel->icoB[i], icon);
  239.         WMSetButtonImage(panel->shaB[i], icon);
  240.         WMReleasePixmap(icon);
  241.         } else {
  242.         wwarning(_("could not load icon file %s"), path);
  243.         }
  244.         free(path);
  245.     }
  246.     path = LocateImage(buf2);
  247.     if (path) {
  248.         icon = WMCreatePixmapFromFile(scr, path);
  249.         if (icon) {
  250.         WMSetButtonAltImage(panel->icoB[i], icon);
  251.         WMSetButtonAltImage(panel->shaB[i], icon);
  252.         WMReleasePixmap(icon);
  253.         } else {
  254.         wwarning(_("could not load icon file %s"), path);
  255.         }
  256.         free(path);
  257.     }
  258.     }
  259.     free(buf1);
  260.     free(buf2);
  261.  
  262.     
  263.     WMMapSubwidgets(panel->icoF);
  264.     WMMapSubwidgets(panel->shaF);
  265.  
  266.  
  267.     /***************** Smoothed Scaling *****************/
  268.     panel->smoF = WMCreateFrame(panel->frame);
  269.     WMResizeWidget(panel->smoF, 115, 110);
  270.     WMMoveWidget(panel->smoF, 18, 115);
  271.     WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));
  272.     WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
  273.                   "the `pixelization' effect. This will slow\n"
  274.                   "down loading of background images considerably."),
  275.                  WMWidgetView(panel->smoF));
  276.  
  277.     panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
  278.     WMResizeWidget(panel->smoB, 64, 64);
  279.     WMMoveWidget(panel->smoB, 25, 25);
  280.     WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
  281.     path = LocateImage(SMOOTH_IMAGE);
  282.     if (path) {
  283.     RImage *image, *scaled;
  284.  
  285.     image = RLoadImage(WMScreenRContext(scr), path, 0);
  286.     free(path);
  287.     
  288.     scaled = RScaleImage(image, 61, 61);
  289.     icon = WMCreatePixmapFromRImage(scr, scaled, 128);
  290.     RDestroyImage(scaled);
  291.     if (icon) {
  292.         WMSetButtonImage(panel->smoB, icon);
  293.         WMReleasePixmap(icon);
  294.     }
  295.  
  296.     scaled = RSmoothScaleImage(image, 61, 61);
  297.     icon = WMCreatePixmapFromRImage(scr, scaled, 128);
  298.     RDestroyImage(scaled);
  299.     if (icon) {
  300.         WMSetButtonAltImage(panel->smoB, icon);
  301.         WMReleasePixmap(icon);
  302.     }
  303.  
  304.     RDestroyImage(image);
  305.     }
  306.  
  307.     WMMapSubwidgets(panel->smoF);
  308.  
  309.     /***************** Titlebar Style Size ****************/
  310.     panel->titlF = WMCreateFrame(panel->frame);
  311.     WMResizeWidget(panel->titlF, 105, 110);
  312.     WMMoveWidget(panel->titlF, 140, 115);
  313.     WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
  314.     
  315.     panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
  316.     WMResizeWidget(panel->newsB, 74, 40);
  317.     WMMoveWidget(panel->newsB, 15, 20);
  318.     WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
  319.     path = LocateImage(NEWS_IMAGE);
  320.     if (path) {
  321.     icon = WMCreatePixmapFromFile(scr, path);
  322.     if (icon) {
  323.         WMSetButtonImage(panel->newsB, icon);
  324.         WMReleasePixmap(icon);
  325.     }
  326.     }
  327.  
  328.     panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
  329.     WMResizeWidget(panel->oldsB, 74, 40);
  330.     WMMoveWidget(panel->oldsB, 15, 60);
  331.     WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
  332.     path = LocateImage(OLDS_IMAGE);
  333.     if (path) {
  334.     icon = WMCreatePixmapFromFile(scr, path);
  335.     if (icon) {
  336.         WMSetButtonImage(panel->oldsB, icon);
  337.         WMReleasePixmap(icon);
  338.     }
  339.     free(path);
  340.     }
  341.  
  342.     WMGroupButtons(panel->newsB, panel->oldsB);
  343.     
  344.     WMMapSubwidgets(panel->titlF);
  345.  
  346.     /**************** Features ******************/
  347.     
  348.     panel->animF = WMCreateFrame(panel->frame);
  349.     WMResizeWidget(panel->animF, 255, 115);
  350.     WMMoveWidget(panel->animF, 255, 10);
  351.     WMSetFrameTitle(panel->animF, _("Animations and Sound"));
  352.     
  353.     panel->animB = WMCreateButton(panel->animF, WBTToggle);
  354.     WMResizeWidget(panel->animB, 64, 64);
  355.     WMMoveWidget(panel->animB, 15, 20);
  356.     WMSetButtonFont(panel->animB, font);
  357.     WMSetButtonText(panel->animB, _("Animations"));
  358.     WMSetButtonImagePosition(panel->animB, WIPAbove);
  359.     createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
  360.     if (icon) {
  361.     WMSetButtonImage(panel->animB, icon);
  362.     WMReleasePixmap(icon);
  363.     }
  364.     if (altIcon) {
  365.     WMSetButtonAltImage(panel->animB, altIcon);
  366.     WMReleasePixmap(altIcon);
  367.     }
  368.     WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
  369.                   "for window miniaturization, shading etc."),
  370.                 WMWidgetView(panel->animB));
  371.  
  372.     panel->supB = WMCreateButton(panel->animF, WBTToggle);
  373.     WMResizeWidget(panel->supB, 64, 64);
  374.     WMMoveWidget(panel->supB, 95, 20);
  375.     WMSetButtonFont(panel->supB, font);
  376.     WMSetButtonText(panel->supB, _("Superfluous"));
  377.     WMSetButtonImagePosition(panel->supB, WIPAbove);
  378.     createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
  379.     if (icon) {
  380.     WMSetButtonImage(panel->supB, icon);
  381.     WMReleasePixmap(icon);
  382.     }
  383.     if (altIcon) {
  384.     WMSetButtonAltImage(panel->supB, altIcon);
  385.     WMReleasePixmap(altIcon);
  386.     }
  387.     WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
  388.                   "animations. These include the `ghosting' of the\n"
  389.                   "dock when it's being moved to the another side\n"
  390.                   "and the explosion animation for undocked icons."),
  391.                 WMWidgetView(panel->supB));
  392.     
  393.     panel->sfxB = WMCreateButton(panel->animF, WBTToggle);
  394.     WMResizeWidget(panel->sfxB, 64, 64);
  395.     WMMoveWidget(panel->sfxB, 175, 20);
  396.     WMSetButtonFont(panel->sfxB, font);
  397.     WMSetButtonText(panel->sfxB, _("Sounds"));
  398.     WMSetButtonImagePosition(panel->sfxB, WIPAbove);
  399.     createImages(scr, rc, xis, SOUND_IMAGE, &altIcon, &icon);
  400.     if (icon) {
  401.     WMSetButtonImage(panel->sfxB, icon);
  402.     WMReleasePixmap(icon);
  403.     }
  404.     if (altIcon) {
  405.     WMSetButtonAltImage(panel->sfxB, altIcon);
  406.     WMReleasePixmap(altIcon);
  407.     }
  408.     WMSetBalloonTextForView(_("Disable/enable support for sound effects played\n"
  409.                   "for actions like shading and closing a window.\n"
  410.                   "You will need a module distributed separately\n"
  411.                   "for this. You can get it at:\n"
  412.                   "http://www.frontiernet.net/~southgat/wmsound"),
  413.                 WMWidgetView(panel->sfxB));
  414.     
  415.     panel->noteL = WMCreateLabel(panel->animF);
  416.     WMResizeWidget(panel->noteL, 235, 28);
  417.     WMMoveWidget(panel->noteL, 10, 85);
  418.     WMSetLabelFont(panel->noteL, font);
  419.     WMSetLabelText(panel->noteL, _("Note: sound requires a module distributed separately"));
  420.     
  421.     WMMapSubwidgets(panel->animF);
  422.     
  423.     /*********** Dithering **********/
  424.     panel->cmapSize = 4;
  425.     
  426.     panel->dithF = WMCreateFrame(panel->frame);
  427.     WMResizeWidget(panel->dithF, 255, 95);
  428.     WMMoveWidget(panel->dithF, 255, 130);
  429.     WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
  430.  
  431.     WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
  432.                   "on displays that support only 8bpp (PseudoColor)."),
  433.                 WMWidgetView(panel->dithF));
  434.     
  435.     panel->dithB = WMCreateSwitchButton(panel->dithF);
  436.     WMResizeWidget(panel->dithB, 235, 32);
  437.     WMMoveWidget(panel->dithB, 15, 15);
  438.     WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
  439.  
  440.     panel->dithL = WMCreateLabel(panel->dithF);
  441.     WMResizeWidget(panel->dithL, 75, 16);
  442.     WMMoveWidget(panel->dithL, 90, 50);
  443.     WMSetLabelTextAlignment(panel->dithL, WACenter);
  444.     WMSetLabelText(panel->dithL, "64");
  445.  
  446.     panel->dithS = WMCreateSlider(panel->dithF);
  447.     WMResizeWidget(panel->dithS, 95, 16);
  448.     WMMoveWidget(panel->dithS, 80, 65);
  449.     WMSetSliderMinValue(panel->dithS, 2);
  450.     WMSetSliderMaxValue(panel->dithS, 6);
  451.     WMSetSliderContinuous(panel->dithS, True);
  452.     WMSetSliderAction(panel->dithS, updateLabel, panel);
  453.     
  454.     panel->dith1L = WMCreateLabel(panel->dithF);
  455.     WMResizeWidget(panel->dith1L, 70, 35);
  456.     WMMoveWidget(panel->dith1L, 5, 50);
  457.     WMSetLabelTextAlignment(panel->dith1L, WACenter);
  458.     WMSetLabelFont(panel->dith1L, font);
  459.     WMSetLabelText(panel->dith1L, _("More colors for applications"));
  460.  
  461.     panel->dith2L = WMCreateLabel(panel->dithF);
  462.     WMResizeWidget(panel->dith2L, 70, 35);
  463.     WMMoveWidget(panel->dith2L, 180, 50);
  464.     WMSetLabelTextAlignment(panel->dith2L, WACenter);
  465.     WMSetLabelFont(panel->dith2L, font);
  466.     WMSetLabelText(panel->dith2L, _("More colors for WindowMaker"));
  467.  
  468.     WMMapSubwidgets(panel->dithF);
  469.     
  470.     WMRealizeWidget(panel->frame);
  471.     WMMapSubwidgets(panel->frame);
  472.     
  473.     if (xis)
  474.     RDestroyImage(xis);
  475.     WMReleaseFont(font);
  476.     
  477.     showData(panel);
  478. }
  479.  
  480.  
  481. static void
  482. storeData(_Panel *panel)
  483. {
  484.     int i;
  485.  
  486.     for (i=0; i<5; i++) {
  487.     if (WMGetButtonSelected(panel->icoB[i]))
  488.         break;
  489.     }
  490.     SetSpeedForKey(i, "IconSlideSpeed");
  491.  
  492.  
  493.     for (i=0; i<5; i++) {
  494.     if (WMGetButtonSelected(panel->shaB[i]))
  495.         break;
  496.     }
  497.     SetSpeedForKey(i, "ShadeSpeed");
  498.  
  499.     SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
  500.     
  501.     SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
  502.     SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
  503.     SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
  504.  
  505.     SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
  506.     
  507.     SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
  508.     SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
  509. }
  510.  
  511.  
  512.  
  513. Panel*
  514. InitConfigurations(WMScreen *scr, WMWindow *win)
  515. {
  516.     _Panel *panel;
  517.  
  518.     panel = wmalloc(sizeof(_Panel));
  519.     memset(panel, 0, sizeof(_Panel));
  520.  
  521.     panel->sectionName = _("Other Configurations");
  522.  
  523.     panel->description = _("Animation speeds, titlebar styles, various option\n"
  524.                "toggling and number of colors to reserve for\n"
  525.                "Window Maker in 8bit displays.");
  526.  
  527.     panel->win = win;
  528.  
  529.     panel->callbacks.createWidgets = createPanel;
  530.     panel->callbacks.updateDomain = storeData;
  531.  
  532.     AddSection(panel, ICON_FILE);
  533.  
  534.     return panel;
  535. }
  536.